Fix rendering glyphs from the cache
authorMatthias Clasen <mclasen@redhat.com>
Mon, 11 Sep 2017 18:45:36 +0000 (14:45 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 11 Sep 2017 18:45:36 +0000 (14:45 -0400)
We were not quite using all the right dimensions.

gsk/gskvulkancolortextpipeline.c
gsk/gskvulkanrenderer.c
gsk/gskvulkanrendererprivate.h
gsk/gskvulkantextpipeline.c

index b3da054ffa538e60d70f4142a095bf5ab89e93a6..6cca24334e1f79478b120912d15fc86c32fca7f4 100644 (file)
@@ -104,8 +104,7 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
   GskVulkanColorTextInstance *instances = (GskVulkanColorTextInstance *) data;
   int i, count;
   int x_position = 0;
-  float ascent;
-  float height;
+  float dx, dy, dw, dh;
 
   count = 0;
   for (i = 0; i < glyphs->num_glyphs; i++)
@@ -126,11 +125,11 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
                                                     &instance->tex_rect[1],
                                                     &instance->tex_rect[2],
                                                     &instance->tex_rect[3],
-                                                    &ascent, &height);
-              instance->rect[0] = x + cx;
-              instance->rect[1] = y + cy - ascent;
-              instance->rect[2] = PANGO_PIXELS_CEIL (gi->geometry.width);
-              instance->rect[3] = height;
+                                                    &dx, &dy, &dw, &dh);
+              instance->rect[0] = x + cx + dx;
+              instance->rect[1] = y + cy + dy;
+              instance->rect[2] = dw;
+              instance->rect[3] = dh;
 
               count++;
            }
index a56fd57d4fec9ba2b14793dc77332225012e7ae5..d9739a02ccef9d4f1fe0552d1bd84f9eef7b03b6 100644 (file)
@@ -419,8 +419,10 @@ gsk_vulkan_renderer_get_glyph_coords (GskVulkanRenderer *self,
                                       float             *ty,
                                       float             *tw,
                                       float             *th,
-                                      float             *ascent,
-                                      float             *height)
+                                      float             *dx,
+                                      float             *dy,
+                                      float             *dw,
+                                      float             *dh)
 {
   GlyphCacheValue *gv;
 
@@ -432,8 +434,10 @@ gsk_vulkan_renderer_get_glyph_coords (GskVulkanRenderer *self,
       *ty = gv->ty;
       *tw = gv->tw;
       *th = gv->th;
-      *ascent = - gv->draw_y;
-      *height = gv->draw_height;
+      *dx = gv->draw_x;
+      *dy = gv->draw_y;
+      *dw = gv->draw_width;
+      *dh = gv->draw_height;
     }
 }
 
@@ -502,10 +506,10 @@ add_to_cache (GlyphCache      *cache,
     return;
 
   cairo_set_scaled_font (cr, scaled_font);
-  cairo_set_source_rgba (cr, 0, 0, 0, 1);
+  cairo_set_source_rgba (cr, 1, 1, 1, 1);
 
   cg.index = glyph;
-  cg.x = cache->x;
+  cg.x = cache->x - value->draw_x;
   cg.y = cache->y0 - value->draw_y;
 
   cairo_show_glyphs (cr, &cg, 1);
@@ -515,7 +519,7 @@ add_to_cache (GlyphCache      *cache,
   cache->x = cache->x + value->draw_width + 1;
   cache->y = MAX (cache->y, cache->y0 + value->draw_height + 1);
 
-  value->tx = cg.x / cache->width;
+  value->tx = (cg.x + value->draw_x) / cache->width;
   value->ty = (cg.y + value->draw_y) / cache->height;
   value->tw = (float)value->draw_width / cache->width;
   value->th = (float)value->draw_height / cache->height;
index fe5b0de4835f4598946cf7ad0f491cb400c8396d..25b90e6c299257c6e213528be84c33dab20ef635 100644 (file)
@@ -37,8 +37,10 @@ void                    gsk_vulkan_renderer_get_glyph_coords            (GskVulk
                                                                          float                  *ty,
                                                                          float                  *tw,
                                                                          float                  *th,
-                                                                         float                  *ascent,
-                                                                         float                  *height);
+                                                                         float                  *dx,
+                                                                         float                  *dy,
+                                                                         float                  *dw,
+                                                                         float                  *dh);
 
 void                    gsk_vulkan_renderer_cache_glyphs                (GskVulkanRenderer      *renderer,
                                                                          PangoFont              *font,
index 81eee308c9c4ac18db07485def3c3fae0ceed113..def6c6e95fb754d19a54d393f79078c1379e25e4 100644 (file)
@@ -112,8 +112,7 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline  *pipeline,
   GskVulkanTextInstance *instances = (GskVulkanTextInstance *) data;
   int i, count;
   int x_position = 0;
-  float ascent;
-  float height;
+  float dx, dy, dw, dh;
 
   count = 0;
   for (i = 0; i < glyphs->num_glyphs; i++)
@@ -134,11 +133,11 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline  *pipeline,
                                                     &instance->tex_rect[1],
                                                     &instance->tex_rect[2],
                                                     &instance->tex_rect[3],
-                                                    &ascent, &height);
-              instance->rect[0] = x + cx;
-              instance->rect[1] = y + cy - ascent;
-              instance->rect[2] = PANGO_PIXELS_CEIL (gi->geometry.width);
-              instance->rect[3] = height;
+                                                    &dx, &dy, &dw, &dh);
+              instance->rect[0] = x + cx + dx;
+              instance->rect[1] = y + cy + dy;
+              instance->rect[2] = dw;
+              instance->rect[3] = dh;
               instance->color[0] = color->red;
               instance->color[1] = color->green;
               instance->color[2] = color->blue;